//- Copyright (c) 2016 Lucky Byte, Inc.
extends ../table

append scripts
  script(src="/js/trlist/index.js")

block form_items
  .field.two.wide
    .ui.calendar.date#start_date(data-end-with="#end_date"
      data-maxdate="#{today()}")
      .ui.input.left.icon.small.compact
        i.calendar.icon
        input(type="text" name="start_date" placeholder="起始日期"
          value="#{start_date || ''}")
  .field.two.wide
    .ui.calendar.date#end_date(data-start-with="#start_date"
      data-maxdate="#{today()}")
      .ui.input.right.icon.small.compact
        input(type="text" name="end_date" placeholder="结束日期"
          value="#{end_date || ''}")
        i.remove.link.icon#date_clear

  .field.two.wide
    .ui.labeled.dropdown.selection.input.small.compact
      input(type="hidden" name="chnl" value="#{chnl || ''}")
      i.icon.dropdown
      .default.text 所有渠道
      .menu
        .item(data-value="") 所有渠道
        - for (var k in constant.chnls)
          .item(data-value="#{k}")= constant.chnls[k]
  .field.two.wide
    .ui.labeled.dropdown.selection.input.small.compact
      input(type="hidden" name="succed" value="#{succed || ''}")
      i.icon.dropdown
      .default.text 所有状态
      .menu
        .item(data-value="") 所有状态
        .item(data-value="true") 成功交易
        .item(data-value="false") 失败交易
  .field.two.wide
    .ui.labeled.dropdown.selection.input.small.compact
      input(type="hidden" name="settl" value="#{settl || ''}")
      i.icon.dropdown
      .default.text 所有交易
      .menu
        .item(data-value="") 所有交易
        .item(data-value="true") 清算交易

  .field.three.wide
    .ui.buttons.right.floated.small.compact
      button.ui.green.button.labeled.icon(type="submit") 查 询
        i.icon.search
      button.ui.blue.button.small.compact.rstat(type="button"
        onclick = "window.location = " +
          "'/trstat?start_date=#{start_date}&end_date=#{end_date}'") 交易统计

block thead
  tr
    th.center.aligned
    th.center.aligned 序 号
    th.center.aligned 时 间
    th.center.aligned 渠 道
    th.center.aligned 交易名称
    th.center.aligned 主账号
    th.center.aligned 交易金额
    th.center.aligned 手续费
    th.center.aligned 商户编号
    th.center.aligned 终端编号
    th.center.aligned 跟踪号
    th.center.aligned 清算
    th.center.aligned 清算日
    th.center.aligned 备 注

block tbody
  each record, index in records
    - record.i_pkt = record.i_pkt || {}
    - record.o_pkt = record.o_pkt || {}

    - var tr_class = ''
    - var chnl_icon_color = 'green'

    case record.chnl
      when 1
        -
          chnl_icon_color = 'green'
          tr_class = record.o_pkt[39] == '00' ? '' : 'warning'
      when 2
        - chnl_icon_color = 'blue'
      when 3
        -
          chnl_icon_color = 'pink'
          if (record.n_pkt)
            tr_class = record.n_pkt.respCode == '00' ? '' : 'warning'
          else
            tr_class = record.o_pkt.respCode == '00' ? '' : 'warning'

    if record.status != 0
      - tr_class = 'error'

    tr(class="#{tr_class}")
      if record.indirect
        td.center.aligned.collapsing(style="background:#ffffe0;")
          if record.incoming
            i.icon.reply.all.link(class="#{chnl_icon_color}"
              style="margin-right:0px;" data-content="平台接收，重组模式"
              data-variation="small")
          else
            i.icon.send.outline.link(class="#{chnl_icon_color}"
              style="margin-right:0px;" data-content="平台发出，重组模式"
              data-variation="small")
      else
        td.center.aligned.collapsing(style="background:#f4f4f4;")
          if record.incoming
            i.icon.reply.all.link(class="#{chnl_icon_color}"
              style="margin-right:0px;" data-content="平台接收，透传模式"
              data-variation="small")
          else
            i.icon.send.outline.link(class="#{chnl_icon_color}"
              style="margin-right:0px;" data-content="平台发出，透传模式"
              data-variation="small")

      td.center.aligned.collapsing
        i.icon.caret.right.link.detail.expand
        = record.serial
      td.center.aligned.collapsing
        = record.sys_time.format('MM-DD HH:mm:ss')
      td.center.aligned.collapsing= constant.chnls[record.chnl]
      td.center.aligned.collapsing= record.trinfo.name
      td.center.aligned.collapsing
        case record.dcflag
          when 1
            i.icon.payment.teal(data-content="借记卡" data-variation="small")
          when 2
            i.icon.payment.orange(data-content="贷记卡" data-variation="small")
          when 99
            i.icon.payment.grey(data-content="未知卡种" data-variation="small")
          default
            i.icon
        = record.pri_acct
      td.center.aligned.collapsing
        = record.trdata[2] ? fmtamt2(record.trdata[2]) : '-'
      td.center.aligned.collapsing= record.fee ? fmtamt(record.fee) : '-'
      td.center.aligned.collapsing= record.trdata[0]
      td.center.aligned.collapsing= record.trdata[1]
      td.center.aligned.collapsing= record.trdata[3]
      td.center.aligned.collapsing
        if record.trinfo.settl
          i.icon.checkmark.grey
      td.center.aligned.collapsing= record.trdata[4]
      td
        case record.status
          when 2
            = record.notes + "，已冲正"
          default
            = record.notes

    tr.detail(style="display: none;")
      td.right.aligned.warning(colspan="1") 详细信息
      td(colspan="13"
        style="padding-top:0px; padding-bottom:0px; padding-right:1px;")
        include detail
  else
    td.center.aligned.warning(colspan="16") 无数据
